package com.hudongwx.sadpw.fragment.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hudongwx.sadpw.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.xutils.x;

/**
 * Author:Literary
 * DateTime:16-12-14 上午9:54
 */
public class MyRecycleAdapter2 extends RecyclerView.Adapter<MyRecycleAdapter2.ViewHolder> {
    JSONArray jsonArray;
    Activity activity;

    public MyRecycleAdapter2(JSONArray jsonArray, Activity activity) {
        this.jsonArray = jsonArray;
        this.activity = activity;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = activity.getLayoutInflater().inflate(R.layout.item_home3, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        try {
            x.image().bind(holder.imageView,jsonArray.getJSONObject(position).getString("CoverUrl"));
            holder.textView.setText(jsonArray.getJSONObject(position).getString("Title"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getItemCount() {
        return jsonArray.length();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        TextView textView;

        public ViewHolder(View itemView) {
            super(itemView);
            imageView= (ImageView) itemView.findViewById(R.id.rel_home3_iv);
            textView= (TextView) itemView.findViewById(R.id.rel_home3_tv);
        }
    }
}
